<?php
namespace app\controllers;
use yii\web\Controller;
use Yii;
class PrintController extends Controller{
    public function actionIndex(){
        if(Yii::$app->request->isPost){
            $postData=  \Yii::$app->request->post();
            $model=  \app\models\GkyQyhUser::findOne(['name'=>$postData['username'],'mobile'=>$postData['phone']]);
            if($model){
                $session=  \Yii::$app->session;
                $session->set('user', $model);
                return $this->redirect(['print']);
            }else{
               return $this->renderPartial('index',
                      ['msg'=>'用户信息错误']); 
            }
        }else{
            return $this->renderPartial('index');
        }
    }
    public function actionPrint(){
        $session=  \Yii::$app->session;
        if(isset($session['user'])){
            if(Yii::$app->request->post('print_code')!=NULL){
                $printCode=Yii::$app->request->post('print_code');
                $index = substr($printCode, 0, 4);
                if($index=='BUSI'){
                    $result = \app\models\GkyQyhSpBusiness::getBusiness($printCode);
                    if($result['status']!=1){
                        echo $index.'不存在，请核实';
                    }else{
                        return $this->renderPartial('business', ['data'=>$result]);
                        
                    }
                }  else if($index=='GOAB') {
                    $result = \app\models\GkyQyhSpGoabroad::getGoabroad($printCode);
                    if($result['status']!=1){
                        echo $index.'不存在，请核实';
                    }else{
                        return $this->renderPartial('goabroad', ['data'=>$result]);
                        
                    }
                } else if($index=='AUTH'){
                    $result = \app\models\GkyQyhSpAuthorization::getAuthorization($printCode);
                    if($result['status']!=1){
                        echo $index.'不存在，请核实';
                    }else{
                        return $this->renderPartial('authorization',['data'=>$result]);
                        
                    }
                }else if($index=='STAT'){
                    $result = \app\models\GkyQyhSpStatement::getStatement($printCode);
                    if($result['status']!=1){
                        echo $index.'不存在，请核实';
                    }else{
                        return $this->renderPartial('statement',['data'=>$result]);
                        
                    }
                }else if($index=='LEAV'){
                    $result = \app\models\GkyQyhSpLeave::getLeave($printCode);
                    if($result['status']!=1){
                        echo $index.'不存在，请核实';
                    }else{
                        return $this->renderPartial('leave',['data'=>$result]);
                        
                    }
                }
                echo $index;
            }else{
                return $this->renderPartial('print_code');
            }
        }else{
            return $this->redirect(['index']);
        }
    }
}